<template>
	<view class="content" :style="{height:winH}">
		<view class="list">
			<uni-list>
				<uni-list-item title="个人信息" thumb-size="sm" link to="userInfo"></uni-list-item>
				<uni-list-item title="用户认证" thumb-size="sm" link @click="goAutonym"></uni-list-item>
				<uni-list-item title="更换手机号" thumb-size="sm" link to="checkPhone"></uni-list-item>
			</uni-list>
		</view>
		<button class="btn-primary" @click="logOut">退出登录</button>
	</view>
</template>
<script setup lang="ts">
	import {ref} from 'vue'
	import {onLoad, onUnload, onShow} from "@dcloudio/uni-app"
	import { getInfo } from '@/common/API/login'
	import store from '@/store'
	const flag = ref(false)
	const winH = ref(uni.getWindowInfo().windowHeight+"px")
	const logOut = () => {
		store.dispatch('logOut');
		uni.redirectTo({
			url:'/pages/login/login'
		})
	}
	
	onUnload(()=>{
		if(!flag.value){
			uni.switchTab({
			    url: '/pages/personal/index',
			})  
		}
	})
	onShow(()=> {
		if(uni.getStorageSync('userId')){
			getInfo().then((res)=>{
				store.dispatch('setUserInfo',res);
			})
		}
	})
	//scene 1 实名回调地址
	onLoad((options)=>{
		if(options){
			flag.value = options.flag
			if(options.scene == 1){
				uni.switchTab({
				    url: '/pages/personal/index',
				})
			}
		}
	})
	
	const goAutonym = () => {
		let userInfo = uni.getStorageSync('userInfo')
		if(userInfo.authenticated){
			uni.showToast({
				title: '已实名认证',
				icon: 'none',
			});
		}else{
			uni.navigateTo({
				url:'/pages/personal/settings/autonym'
			})
		}
	}
</script>
<style lang="scss" scoped>
.content{
	padding: 16rpx 32rpx;
	.list{
		border: 2rpx solid #e5e5e5;
		margin-bottom: 100rpx;
		::v-deep.uni-list{
			.uni-list--border-top,.uni-list--border-bottom{
				display: none !important;
			}
			.uni-list-item__icon-img{
				margin: 0;
			}
		}
	}
	.btn-primary{
		border-radius: 10rpx;
		width: 550rpx;
	}
}
</style>
